#from os.path import join, exists
import os
import logging
from forest.api import Command, get_tool
#import ConfigParser

logger = logging.getLogger('forest.commands.SSHKeygen')

class SSHKeygen(Command):
    ''' Sets up ssh servers in the tree.

        Example::

            ssh: True

        .. describe:: ssh_keygen

            should it generate the host keys files (boolean)
    '''
    __register__ = 'commands.setup.SSHKeygen'

    def run(self, config):
        self.args = config.get('ssh_keygen', True)

        if self.args is None:
            return

        ssh_hostkey = config.join_install_root('etc', 'ssh', 'ssh_host_rsa_key')

        if not os.path.exists(ssh_hostkey):
            get_tool('system.execute')(['ssh-keygen', '-qot', 'rsa', '-f', ssh_hostkey, '-P', ''])


